//Program to replace text string from tex file
cap program drop replace_tex
program define replace_tex, nclass 
	local tex_file `1'
	local from `2'
	local to `3'
	tempfile t
	filefilter "`tex_file'" "`t'", from("`from'") to("`to'") replace
	copy "`t'" "`tex_file'", replace
end

//Common 
cap program drop tex_edits
program define tex_edits
	syntax, file(string)
	sleep 500
	replace_tex "`file'" "\BSbegin{table}[h] \BScentering" " "
	sleep 200
	replace_tex "`file'" "\BSend{table}" " "
	sleep 200
	replace_tex "`file'" "\BSnewcolumntype{C}{>{\BScentering\BSarraybackslash}X}" " "
	sleep 200
	replace_tex "`file'" "\BSnewcolumntype{R}{>{\BSraggedleft\BSarraybackslash}X}" " "
	sleep 200
	replace_tex "`file'" "\BSnewcolumntype{L}{>{\BSraggedright\BSarraybackslash}X}" " "	
	sleep 200
	replace_tex "`file'" "\BSmidrule \BSaddlinespace[\BSbelowrulesep]" " "
	sleep 200
	replace_tex "`file'" "{\BSlinewidth}" " "
	sleep 200
	replace_tex "`file'" "{tabularx}" "{tabular}"
	sleep 200
end
